<!--  -->
<template>
  <div class="">
    1、如何统计字符串“ aaaabbbccccddfgh”中字母的个数或统计最多的字母数？
  </div>
</template>

<script setup lang="ts">
import {} from 'vue';
const str1 = 'aaabbbccccddaaaafgh';
const result1 = str1.split('').reduce((pre, cur, idx) => {
  if(pre[cur]){
    pre[cur] = Number(pre[cur]) + 1;
  }else {
    pre[cur] = 1;
  }
  return pre;
}, {});
console.log('字母的个数或统计最多的字母数', Math.max(...Object.values(result1)));

</script>


<style lang="scss" scoped>

</style>
